﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
    public class Ctbl_Group_Khachhang:IData<tbl_Group_Khachhang>
    {
        public Ctbl_Group_Khachhang(String myconnecString) : base(myconnecString) { }

        public override List<tbl_Group_Khachhang> GetAll(tbl_Group_Khachhang item)
        {
            throw new NotImplementedException();
        }

        public override tbl_Group_Khachhang GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p => p.IdGroup == Convert.ToInt32(id));
        }

        public override tbl_Group_Khachhang GetItem(IDataReader dr)
        {
            tbl_Group_Khachhang obj = new tbl_Group_Khachhang();
            obj.IdGroup = Convert.ToInt32(dr[tbl_Group_Khachhang.c_idGroup]);
            obj.IsActive = Convert.ToInt32(dr[tbl_Group_Khachhang.c_isActive]);
            obj.NameGroup = Convert.ToString(dr[tbl_Group_Khachhang.c_nameGroup]);
            obj.OrderId = Convert.ToInt32(dr[tbl_Group_Khachhang.c_orderId]);
            return obj;
        }

        public override List<tbl_Group_Khachhang> GetAll()
        {
            String strSQL = "select * from " + tbl_Group_Khachhang.b_tbl_Group_Khachhang + strAsc;
            return GetAll(strSQL, CommandType.Text);
        }


        protected override int InsertOnSubmit(tbl_Group_Khachhang item, int t)
        {
            int id = -1;
            String strProName = "";
            id = connec.ExecuteNonQuery(strProName, CommandType.StoredProcedure, new SqlParameter("@flag", t),
                new SqlParameter("@"+tbl_Group_Khachhang.c_idGroup,item.IdGroup),new SqlParameter("@"+tbl_Group_Khachhang.c_isActive,item.IsActive),
                new SqlParameter("@"+tbl_Group_Khachhang.c_nameGroup,item.NameGroup),new SqlParameter("@"+tbl_Group_Khachhang.c_orderId,item.OrderId));
            return id;
        }
    }
}
